package com.doit.day02

import com.doit.Test.Person

/**
 * scala中第一重要东西
 *  函数是个啥呢？其实从功能上来讲，函数和方法一样
 *  也是一段代码逻辑的封装 便于后续调用，提高代码的复用性
 *  定义的语法有点不一样
 *
 *  但是注意：函数的本质和方法有天差地别   函数的本质是一个接口的实现类对象
 */
object _01_函数 {
  def main(args: Array[String]): Unit = {

    val i: Int = getMax.apply(1, 2, 3)
    getMax(1,2,3)


  }

  //(Int,(Int)=>String)=> ((Int)=>String)=>Unit
  val res7: (Int, Int => String) => (Int => String) => Unit = (a:Int, b:(Int)=>String)=>{
    val aaa = (c:(Int)=>String)=>{}
    aaa
  }

  val apply = (a:Int,b:Int)=>{a+b}





  val getMax:Function3[Int,Int,Int,Int] = (a:Int,b:Int,c:Int)=>{
    var max = a
    if(max < b ) max = b
    if(max < c ) max = c
    max
  }
   // (Int, Int, Int)=> Int   语法糖的写法
  val getMax1:(Int, Int, Int) => Int = (a:Int, b:Int, c:Int)=>{
    var max = a
    if(max < b ) max = b
    if(max < c ) max = c
    max
  }

  //(String,Int)=>String
  val res1:Function2[String,Int,String] = (a:String,b:Int)=>{
    a+b+""
  }

  //()=>Unit
  val res2:() => Unit = ()=>{
    println("hehe")
  }

  // (Person,Int,String)=>Unit
  val res3:(Person, Int, String) => Unit = (p:Person, a:Int, b:String)=>{
    println("nihao")
  }


  //(Int,Person,(Int,Int)=>Int)=>Unit
  val res4 :Function3[Int,Person,Function2[Int,Int,Int],Unit]= (a:Int,b:Person,c:Function2[Int,Int,Int])=>{
    val person: Person = new Person()
  }

  //()=> (Int,Int)=> Int
  val res5: () => (Int, Int) => Int = ()=>{
    val function = new Function2[Int, Int, Int] {
      override def apply(v1: Int, v2: Int) = 1
    }
    function
  }

  // ((Int)=>String,Int)=>String
  val res6:Function2[Function1[Int,String],Int,String] = (a:Function1[Int,String],b:Int)=>{
    a.apply(b)
  }





}
